home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0057_Expand a path to TOutlineNode.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-24  |  2.9 KB  |  79 lines

  1. {
  2.         How to expand a path to a TOutlineNode referenced by Index
  3.  
  4. This is a routine from my forthcoming application Information Manager V1.0.
  5. I thought that it might be interesting to others, so I'm contributing it to
  6. the public.
  7.  
  8. The purpose I wrote this routine was, that I had an index from a TOutlineNode
  9. (which was the result of search) and wanted to expand a path to the node
  10. without expanding unnecessary trees.
  11.  
  12. The following routine accepts an index as a parameter and expands the path
  13. to the TOutlineNode with this index.
  14.  
  15. The routine assumes a TOutline object named Outline.
  16. }
  17.  
  18. var
  19.   Outline: TOutline;
  20.  
  21. procedure TSearchDlg.ExpandPathToFoundItem(const FoundItemIndex: Longint);
  22. {------------------------------------------------------------------------------
  23.  Expands a path to a given item (item is specified by the index number). Only
  24.  the parents needed to get to the specified item will be expanded.
  25.  -----------------------------------------------------------------------------}
  26. var
  27.   ItemIndex:   Longint;
  28.   Found:       Boolean;
  29.   LastCh:      Longint;
  30.   Path:        String;
  31.   ItemText:    String;
  32.   SepPos:      Integer;
  33.   OldSep:      String;
  34. begin
  35.   {Save the old ItemSpearator}
  36.   OldSep:=Outline.ItemSeparator;
  37.   {Set the new ItemSeparator}
  38.   Outline.ItemSeparator:='\';
  39.   {Get the full path to the TOutlineNode and add a '\'. This is done, because it
  40.    simplifies the whole algorithm}
  41.   Path:=Outline.Items[FoundItemIndex].FullPath+'\';
  42.   {As long as the end of the path has not been reached}
  43.   while Length(Path) > 0 do begin
  44.     {Determine the position of the first '\' in the path}
  45.     SepPos:=Pos('\',Path);
  46.     {Isolate the TOutlineNode item}
  47.     ItemText:=Copy(Path,1,SepPos-1);
  48.     {Determine the index of the TOutlineNode}
  49.     ItemIndex:=Outline.GetTextItem(ItemText);
  50.     {Expand it}
  51.     Outline.Items[ItemIndex].Expand;
  52.     {Cut the expanded TOutlineNode from the string}
  53.     Path:=Copy(Path,SepPos+1,Length(Path)-SepPos+1);
  54.   end;
  55.   {Restore original ItemSeparator}
  56.   Outline.ItemSeparator:=OldSep;
  57. end;
  58.  
  59.  
  60. DETAILS
  61.  
  62. Let's assume the full path to the desired item is:
  63.  
  64.         "My Computer\Hardware\SoundCard\Base Adress"
  65.  
  66. The first step returns the above path. Then the substring "My Computer" is
  67. isolated. Then the index of the TOutlineNode "My Computer" is determined by
  68. using the "GetTextItem" method. The "Expand" method expands this tree.
  69. Afterwards "My Computer" is cut from the path resulting in the new path
  70. "Hardware\SoundCard\Base Adress".
  71.  
  72. Then the index of "Hardware" is determined, expanded and again, cut away.
  73. This procedure repeats until there is no path left to expand. Then the path
  74. to the given TOutlineNode will be expanded.
  75.  
  76. If you have any questions or comments, you can reach me by e-mail at
  77. Christian.Feichtner@jk.uni-linz.ac.at or you might want to have a look
  78. at my homepage: http://www.cam.org/~psarena/cfeichtner
  79.